//
//  AssetsScrollView.m
//  DBAChain
//
//  Created by Mxionlly on 2018/9/7.
//  Copyright © 2018年 Evan. All rights reserved.
//

#import "AssetsScrollView.h"
#import "AssetsBannerView.h"
#import "CommonData.h"
#import "ApageControl.h"

@interface AssetsScrollView ()<UIScrollViewDelegate>
{
    UIScrollView  *scrollerView;
    UIPageControl *pageControl;
    ApageControl  *pageCtrl;
}
@end

@implementation AssetsScrollView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initialize];
    }
    return self;
}

- (void)initialize
{
    UILabel *lbtitle = [[UILabel alloc]initWithFrame:CGRectMake(30, 10, CGRectGetWidth(self.bounds) - 60, 20)];
    lbtitle.font = [UIFont boldSystemFontOfSize:15];
    lbtitle.textColor = [UIColor whiteColor];
    lbtitle.textAlignment = NSTextAlignmentCenter;
    lbtitle.text = @"主账户";
    [self addSubview:lbtitle];
    
    scrollerView = [[UIScrollView alloc]init];
    scrollerView.delegate = self;
    scrollerView.showsHorizontalScrollIndicator = false;
    scrollerView.backgroundColor = [UIColor clearColor];
    scrollerView.frame = CGRectMake(0, CGRectGetMaxY(lbtitle.frame)+10, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)-(CGRectGetMaxY(lbtitle.frame)+20));
    [self addSubview:scrollerView];
    
    
    pageCtrl = [[ApageControl alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.bounds)-10, CGRectGetWidth(self.bounds), 5)];
    pageCtrl.numberOfPages = 2;
    pageCtrl.currentPage = 0;
    pageCtrl.userInteractionEnabled = NO;
    pageCtrl.currentImageSizeW = 30;
    pageCtrl.currentImageSizeH = 6;
    pageCtrl.currentPageIndicatorTintColor = [UIColor clearColor];
    pageCtrl.pageIndicatorTintColor = [UIColor clearColor];
    [self addSubview:pageCtrl];
}

-(void)setItems:(NSMutableArray *)items
{
    _items = items;
    for (int i = 0; i < items.count; i++) {
        AssetsBannerView *bannerView = [AssetsBannerView getbannerView];
        bannerView.frame = CGRectMake(CGRectGetWidth(self.bounds)*i, 0, CGRectGetWidth(self.bounds), 150);
        [scrollerView addSubview:bannerView];
    }
    scrollerView.contentSize = CGSizeMake(CGRectGetWidth(self.bounds)*items.count, CGRectGetHeight(scrollerView.frame));
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat contenOffset = scrollView.contentOffset.x;
    int page = contenOffset/CGRectGetWidth(scrollView.frame);
    pageCtrl.currentPage = page;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    CGFloat contenOffset = scrollView.contentOffset.x;
    int page = contenOffset/CGRectGetWidth(scrollView.frame);
    pageCtrl.currentPage = page;
    if ([self.delegate respondsToSelector:@selector(didAssetsScrollWithGTE:)]) {
        [self.delegate didAssetsScrollWithGTE:page == 0 ? YES : NO];
    }
}

-(void)setDataInfoArray:(NSMutableArray *)dataInfoArray{
    for (int i = 0; i < dataInfoArray.count; i++) {
        dataOverviewInfo *info = dataInfoArray[i];
        AssetsBannerView *bannerView  = scrollerView.subviews[i];
        bannerView.lbtitle.text = [NSString stringWithFormat:@"总资产折合(%@)",info.dataName];
        bannerView.labelBiTotalAmount.text = info.totalAmount;
        bannerView.labelBiFreezeAmount.text = [NSString stringWithFormat:@"冻结资产：%@ %@",info.freezeAmount,info.dataName];
    }
}

@end
